package com.ruoyi.SSL.controller;

import java.util.List;

import com.ruoyi.SSL.domain.SslTrusteeshipService;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.domain.entity.SysDept;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.SSL.domain.SslTrusteeshipServiceDomain;
import com.ruoyi.SSL.service.ISslTrusteeshipServiceDomainService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 托管域名管理Controller
 *
 * @author ruoyi
 * @date 2024-09-27
 */
@Controller
@RequestMapping("/SSL/domain")
public class SslTrusteeshipServiceDomainController extends BaseController
{
    private String prefix = "SSL/domain";

    @Autowired
    private ISslTrusteeshipServiceDomainService sslTrusteeshipServiceDomainService;

    @RequiresPermissions("SSL:domain:view")
    @GetMapping()
    public String domain()
    {
        return prefix + "/domain";
    }

    /**
     * 查询托管域名管理列表
     */
    @RequiresPermissions("SSL:domain:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SslTrusteeshipServiceDomain sslTrusteeshipServiceDomain)
    {
        startPage();
        List<SslTrusteeshipServiceDomain> list = sslTrusteeshipServiceDomainService.selectSslTrusteeshipServiceDomainList(sslTrusteeshipServiceDomain);
        return getDataTable(list);
    }

    /**
     * 导出托管域名管理列表
     */
    @RequiresPermissions("SSL:domain:export")
    @Log(title = "托管域名管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SslTrusteeshipServiceDomain sslTrusteeshipServiceDomain)
    {
        List<SslTrusteeshipServiceDomain> list = sslTrusteeshipServiceDomainService.selectSslTrusteeshipServiceDomainList(sslTrusteeshipServiceDomain);
        ExcelUtil<SslTrusteeshipServiceDomain> util = new ExcelUtil<SslTrusteeshipServiceDomain>(SslTrusteeshipServiceDomain.class);
        return util.exportExcel(list, "托管域名管理数据");
    }

    /**
     * 新增托管域名管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存托管域名管理
     */
    @RequiresPermissions("SSL:domain:add")
    @Log(title = "托管域名管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SslTrusteeshipServiceDomain sslTrusteeshipServiceDomain)
    {
        return toAjax(sslTrusteeshipServiceDomainService.insertSslTrusteeshipServiceDomain(sslTrusteeshipServiceDomain));
    }

    /**
     * 修改托管域名管理
     */
    @RequiresPermissions("SSL:domain:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SslTrusteeshipServiceDomain sslTrusteeshipServiceDomain = sslTrusteeshipServiceDomainService.selectSslTrusteeshipServiceDomainById(id);
        mmap.put("sslTrusteeshipServiceDomain", sslTrusteeshipServiceDomain);
        return prefix + "/edit";
    }

    /**
     * 修改保存托管域名管理
     */
    @RequiresPermissions("SSL:domain:edit")
    @Log(title = "托管域名管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SslTrusteeshipServiceDomain sslTrusteeshipServiceDomain)
    {
        return toAjax(sslTrusteeshipServiceDomainService.updateSslTrusteeshipServiceDomain(sslTrusteeshipServiceDomain));
    }

    /**
     * 删除托管域名管理
     */
    @RequiresPermissions("SSL:domain:remove")
    @Log(title = "托管域名管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sslTrusteeshipServiceDomainService.deleteSslTrusteeshipServiceDomainByIds(ids));
    }


    @ResponseBody
    @GetMapping("/queryServiceTree")
    public List<Ztree> queryServiceTree()
    {
        return sslTrusteeshipServiceDomainService.selectTree(new SslTrusteeshipService());
    }
}
